//
//  user_interface.c
//  smart_garbage_case
//
//  Created by fukai,caihui on 2018/11.
//  Copyright © 2018年 Cyber01. All rights reserved.
//

#include "key.h"
#include "adc.h"
#include "oled.h"
#include "user_interface.h"
#include "action_ctrl.h"


OledDisplayCfgNode OledDisplayCfg = 
{
	.oled_menu = 0,
	.oled_line = 0,
};


//功能选择
void FunctionSelection(void)
{
	KeyMessage.KeyValue = KeyScan();
	
	switch(KeyMessage.KeyValue)
	{
		case KEY_NULL:
			break;
		case KEY_START:
			MotorStatusChange();
			break;
		case KEY_MENU:
			OledCls();
			OledDisplayCfg.oled_menu++;
			if(OledDisplayCfg.oled_menu >= 2)
			{
				OledDisplayCfg.oled_menu = 0;
			}
			break;
		case KEY_DIRECTION_UP:
			OledCls();
			OledDisplayCfg.oled_line--;
			if(OledDisplayCfg.oled_line < 0)
			{
				OledDisplayCfg.oled_line = 7;
			}
			break;
		case KEY_DIRECTION_DOWN:
			OledCls();
			OledDisplayCfg.oled_line++;
			if(OledDisplayCfg.oled_line > 7)
			{
				OledDisplayCfg.oled_line = 0;
			}
			break;
		case KEY_ADD:
			break;
		case KEY_DECREASE:
			break;
	}
}

//参数调节
 void DebugParameter(void)
 {
	 switch(OledDisplayCfg.oled_menu)
	 {
		 case 0:
			 switch(OledDisplayCfg.oled_line)
			 {
				 case 0:
					 break;
				 case 1:
					 break;
				 case 2:
					 DebugI(&y_times,1);
					 break;
				 case 3:
					 DebugI(&x_times,1);
					 break;
				 case 4:
					 DebugI(&z_times,1);
					 break;
				 case 5:
					 DebugI(&turn_speed,1);
					 break;
				 case 6:
					 break;
				 case 7:
					 break;
			 }
			 break;
	 }
 }


//OLED屏幕显示
void OledDisplay(void)
{
	switch(OledDisplayCfg.oled_menu)
	{
		case 0:
			OledShow6x8Str(6*0,0,"ServoStatus");OledPrintValueI(6*12,0,ActionCtrl.ServoCtrl.ServoAcFlag);
			OledShow6x8Str(6*0,1,"MotorStatus");OledPrintValueI(6*12,1,ActionCtrl.MotorCtrl.MotorACFlag);
//			OledShow6x8Str(6*0,2,"F_L_PWM");OledPrintValueI(6*12,2,ActionCtrl.MotorCtrl.front_left_pwm);
//			OledShow6x8Str(6*0,3,"F_R_PWM");OledPrintValueI(6*12,3,ActionCtrl.MotorCtrl.front_right_pwm);
//			OledShow6x8Str(6*0,4,"R_L_PWM");OledPrintValueI(6*12,4,ActionCtrl.MotorCtrl.rear_left_pwm);
//			OledShow6x8Str(6*0,5,"R_R_PWM");OledPrintValueI(6*12,5,ActionCtrl.MotorCtrl.rear_right_pwm);
			OledShow6x8Str(6*0,2,"y_times");OledPrintValueI(6*12,2,y_times);
			OledShow6x8Str(6*0,3,"x_times");OledPrintValueI(6*12,3,x_times);
			OledShow6x8Str(6*0,4,"z_times");OledPrintValueI(6*12,4,z_times);
			OledShow6x8Str(6*0,5,"turn_speed");OledPrintValueI(6*12,5,turn_speed);
			OledShow6x8Str(6*0,6,"InfraredAd");OledPrintValueI(6*12,6,AdcValue.front_infrared_ad);
			OledShow6x8Str(110,OledDisplayCfg.oled_line,"<-");
			break;
		
		case 1:
			break;
	}
}


//用户界面显示
void UserInterface(void)
{
	FunctionSelection();//功能选择
	DebugParameter();//参数调节
	OledDisplay();//OLED屏幕显示
}











